#include "AreaChart.h"
#include "../../common/utility.h"
#include <QMessageBox>
#include "../../gui/MainWindow/MainWindow.h"

namespace LightChart
{
    AreaChart::AreaChart(QWidget* parent) : BasicAreaChart(), AreaChartGUI(parent)
    {
    }
    void AreaChart::showOptions()
    {
	show();
	try
	{
	    title = lineEditTitle->text().toStdString();
	    bgColor = get_color();
	    if(!lineEditWidth->text().isEmpty())
	    {
		double tmp = QStringToDouble(lineEditWidth->text());
		if(tmp < 100 || tmp > 1920) throw std::runtime_error("Wrong width specified. Width must be in [100 : 1920]");
		else windowWidth = tmp;
	    }
	    if(!lineEditHeight->text().isEmpty())
	    {
		double tmp = QStringToDouble(lineEditHeight->text());
		if(tmp < 50 || tmp > 1080) throw std::runtime_error("Wrong height specified. Height must be in [50 : 1080]");
		else windowHeight = tmp;
	    }
	    static_cast<MainWindow*>(this->parentWidget())->RefreshAll();
	}
	catch(const std::runtime_error& e)
	{
	    QMessageBox::critical(this,"Input data corrupted.",e.what());
	}
    }
    void AreaChart::draw()
    {
	PlotWindow* plotWindow = new PlotWindow(parentWidget());
	qwtAreaChart adapter(*this);
	adapter.preparePlot(plotWindow->get_plot());
	plotWindow->show();
    }
    std::vector<Axis*> AreaChart::get_axes()
    {
	return BasicAreaChart::get_axes();
    }
}

